import React, { Component } from 'react'
import './index.css'

export default class Footer extends Component {
  handleAllChecked = (e) => {
    console.log(e.target.checked);
    this.props.checkAllTodo(e.target.checked)
  }

  // 删除所有已完成的回调
  handleClearAllDone = () => {
    this.props.clearAllDone();
  }

  render() {
    const { todos } = this.props;
    // 已完成的
    const doneCount = todos.reduce((pre, current) => pre + (current.done ? 1 : 0), 0)
    // 总数
    const totals = todos.length;

    return (
      <>
        <div className="todo-footer">
          <label>
            <input onChange={this.handleAllChecked} checked={doneCount === totals && totals !== 0 ? true : false} type="checkbox" />
          </label>
          <span>
            <span>已完成{doneCount}</span> / 全部{totals}
          </span>
          <button onClick={this.handleClearAllDone} className="btn btn-danger">清除已完成任务</button>
        </div>
      </>
    )
  }
}
